home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / UTILS / LZAPI32.ZIP / MSC.ZIP / TEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-05  |  5.3 KB  |  175 lines

  1.  
  2.  
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #ifdef __BORLANDC__
  7. # include <alloc.h>
  8. #else
  9. # include <malloc.h>
  10. #endif
  11.  
  12. #if !defined(__BORLANDC__) && defined(WIN32)
  13. # define _export
  14. #endif
  15.  
  16.  
  17. #include "lzapi.h"           // Needed for any Program that uses LZAPI
  18.  
  19. static int wdth=0, run=0;
  20.  
  21. int FAR PASCAL _export ExampleCallback(int msg, LPLACTL Ctl)
  22. { switch (msg) {
  23.     case LAM_NEXTFILE:     printf("\nFile: %-20s ", Ctl->lpstrProcessedFile);
  24.                wdth = 0;
  25.                break;    
  26.  
  27.     case LAM_MAPNAME:       if (!lstrcmpi(Ctl->lpstrProcessedFile, "WIN.INI"))
  28.                 lstrcpy ((LPSTR) Ctl->lpstrProcessedFile, "EIEIEI.EIE");
  29.                break;
  30.  
  31.     case LAM_PERCENTOFFILE: {
  32.             int nwdth = Ctl->uPercentOfFile * 40 / 100,
  33.             diff  = nwdth - wdth;
  34.             wdth = nwdth;
  35.  
  36.             while (diff--)
  37.                printf("o");
  38.             break;
  39. /*    case LAM_PEEK:  printf("%c\x8", "-\|/-\|/"[(run++)%8]);
  40.             break;*/
  41.     }
  42.   }
  43.   return 0;
  44. }
  45.  
  46.  
  47. main()
  48. { LACTL    Ctl;               // LZAPI Control-Structure.
  49.   char     TempDir[130],       // File-Name for a File in the Temp Directory
  50.        TempFile[130],
  51.        WindowsDirectory[50];   // Directory-Name of the Windows-Directory with the INI-Files
  52.   LAERR    err;               // Errorcode Return-Variable from LZAPI-Function Call
  53.   DWORD       StartTime;
  54.  
  55.   // ------ Increase Handle-Usability for TEST-Purposes ----
  56. /* { int DummyCount;
  57.    OFSTRUCT dummy;
  58.    SetHandleCount(50);
  59.    for (DummyCount=0; DummyCount<40; ++DummyCount)
  60.     _lopen("C:\\AUTOEXEC.BAT", OF_READ | OF_SHARE_DENY_NONE);
  61.  } */
  62.  
  63.   // ------ LACTL-Size -------------------------------------
  64.   printf("sizeof(LACTL) = %d\n", sizeof(LACTL));
  65.  
  66.   // ------ Get Windows Directory --------------------------
  67.   GetWindowsDirectory( WindowsDirectory, sizeof(WindowsDirectory) );
  68.  
  69.   // ----- Get Temp-Directory ------------------------------
  70. # ifdef WIN32
  71.   GetTempPath(sizeof(TempDir), TempDir);
  72. # else
  73.   GetTempFileName(0, "LZH", 0, TempDir);
  74.   OpenFile( TempDir, &dummy, OF_DELETE);
  75.   strrchr(TempDir, '\\')[1] = 0;
  76. # endif
  77.  
  78. //  strcat (strcpy(TempFile, TempDir), "INIS.LZH");
  79. //  strcat (strcpy(TempFile, TempDir), "INIS.ARC");
  80. //  strcat (strcpy(TempFile, TempDir), "INIS.ZOO");
  81.   strcat (strcpy(TempFile, TempDir), "INIS.ZIP");
  82. //  strcat (strcpy(TempFile, TempDir), "INIS.ARC");
  83. // strcpy(TempFile, "A:\\TEST.LZH");
  84.  
  85.   // -------- Initialize Control Structure -----------------
  86.   memset(&Ctl, 0, sizeof(Ctl) );
  87.   Ctl.lStructSize = sizeof(Ctl);
  88.   Ctl.hwndOwner   = NULL;        // This Parameter is Recommended to hold
  89.                     // Your applications main Window
  90.   Ctl.lpfnCallback= ExampleCallback;
  91.  
  92.   // -------- Tell it, what to do --------------------------
  93.   Ctl.lpstrArchivFile = TempFile;     // For example C:\\TMP\INIS.LZH
  94.   Ctl.lpstrPath       = WindowsDirectory;// For example C:\\WINDOWS
  95.   Ctl.lpstrWildcards  = "*.INI *.BAK";     // All INI-Files
  96.   Ctl.Flags          = LAF_SHORTNAMES;  // Recommended Option
  97.  
  98. /*  Ctl.lpstrPath      = "H:\\LOGISDBF";
  99.   Ctl.lpstrWildcards = "*.DB*"; */
  100. //  strcpy(TempFile, "H:\LANGERDATEINAME.ZIP");
  101.  
  102.  
  103.   // -------- Inform user what we are going to do ----------
  104.   printf("SIMPLE.C ---- Simple C-Code example for LZAPI\n"
  105.      "I'm going to Archive %Fs\\%Fs into Archiv %Fs\n",
  106.      Ctl.lpstrPath,
  107.      Ctl.lpstrWildcards,
  108.      Ctl.lpstrArchivFile);
  109.  
  110.   // -------- Perform Actions ------------------------------
  111.   StartTime = GetCurrentTime();
  112. //  err = ZIPAppend( &Ctl );
  113. //  err = LZHAppend( &Ctl );
  114.   err = LAAppend( &Ctl );
  115. //  err = ZOOAppend( &Ctl );
  116.   if (err != LAE_OK)
  117.        { LAErrMsg(err, &Ctl );
  118.          return 5;            // Cancel immediatly
  119.        }
  120.       else { printf("Needed %ld Milliseconds", GetCurrentTime()-StartTime);
  121.          MessageBox( 0, "Hi, this was your Success for Today ;-)", "SIMPLE.C", MB_OK | MB_ICONINFORMATION);
  122.        }
  123.  
  124.   printf("I'm going to list the Archiv %Fs\n", Ctl.lpstrArchivFile);
  125.  
  126.   // -------- Let's show what we have done -----------------
  127. #ifdef NEIN
  128. //  strcpy(TempFile, "C:\\AWORK\\PSUPP\\LZAPI\\TEST.ZOO");
  129.   Ctl.lpstrArchivFile = TempFile;     // Leave unchanged
  130.   Ctl.lpstrWildcards  = NULL;            // Show all Files
  131.   Ctl.lpstrListing    = (char *) malloc(10000U); // Buffer for Listing
  132. //  err = LAList( &Ctl );
  133. //  err = LZHList( &Ctl );
  134.   err = LAList( &Ctl );
  135. //  err = ZIPList( &Ctl );
  136. //  err = ZOOList( &Ctl );
  137.   if (err != LAE_OK)
  138.        { LAErrMsg(err, &Ctl );
  139.          return 5;            // Cancel immediatly
  140.        }
  141.       else MessageBox( 0, "Listing buffer has Successfully been filled", "SIMPLE.C", MB_OK | MB_ICONINFORMATION);
  142.  
  143.   printf("Archiv Listing: \n"
  144.      "%Fs\n",
  145.      Ctl.lpstrListing);
  146.  
  147.   free(Ctl.lpstrListing);
  148. #endif
  149.   printf("I'm going to decompress Archiv %Fs\n", Ctl.lpstrArchivFile);
  150.  
  151.   if (TempDir[lstrlen(TempDir)-1]=='\\')
  152.       TempDir[lstrlen(TempDir)-1]=0;
  153.  
  154.   Ctl.lpstrPath      = TempDir;
  155.   Ctl.lpstrWildcards = "*.*";     // All INI-Files
  156.  
  157.   StartTime = GetCurrentTime();
  158. //  err = ZIPExtract( &Ctl );
  159.   err = LAExtract( &Ctl );
  160. //  err = ZIPExtract( &Ctl );
  161.   if (err != LAE_OK)
  162.        { LAErrMsg(err, &Ctl );
  163.          return 5;            // Cancel immediatly
  164.        }
  165.       else { printf("Needed %ld Milliseconds", GetCurrentTime()-StartTime);
  166.          MessageBox( 0, "Decompression has been performed Successfully", "SIMPLE.C", MB_OK | MB_ICONINFORMATION);
  167.        }
  168.  
  169.   // --------- End Program ---------------------------------
  170.   return 0;
  171.  
  172. //  ARCAppend(&Ctl);
  173. }
  174.  
  175.